package o;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build.VERSION;
import java.util.concurrent.ConcurrentHashMap;

public final class PermissionChecker {
    private static ConcurrentHashMap<Integer, Boolean> ˏ = new ConcurrentHashMap<Integer, Boolean>() {
        {
            put(Integer.valueOf(11), Boolean.valueOf(false));
            put(Integer.valueOf(12), Boolean.valueOf(false));
            put(Integer.valueOf(13), Boolean.valueOf(false));
            put(Integer.valueOf(14), Boolean.valueOf(false));
            put(Integer.valueOf(15), Boolean.valueOf(false));
            put(Integer.valueOf(16), Boolean.valueOf(false));
        }
    };

    public static void ˎ(ceh o_ceh, int i, String[] strArr, int[] iArr) {
        ˏ.put(Integer.valueOf(i), Boolean.valueOf(false));
        if (iArr == null || iArr.length == 0) {
            o_ceh.ˏ(i, -1);
            return;
        }
        for (int i2 : iArr) {
            if (i2 == -1) {
                o_ceh.ˏ(i, -1);
                return;
            }
        }
        o_ceh.ˏ(i, 0);
    }

    public static String[] getPermissionString(int i) {
        if (i == 12 || i == 13 || i == 16) {
            return new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"};
        } else if (i == 11) {
            return new String[]{"android.permission.ACCESS_COARSE_LOCATION"};
        } else if (i == 14) {
            return new String[]{"android.permission.READ_PHONE_STATE"};
        } else if (i != 15) {
            return null;
        } else {
            return new String[]{"android.permission.GET_ACCOUNTS"};
        }
    }

    public static boolean ˋ(Activity activity, int i) {
        if (ˏ.get(Integer.valueOf(i)) == null || !((Boolean) ˏ.get(Integer.valueOf(i))).booleanValue()) {
            return ˏ(getPermissionString(i), activity, true, i);
        }
        return false;
    }

    @TargetApi(23)
    public static void ˎ(Activity activity, int i) {
        if ((ˏ.get(Integer.valueOf(i)) == null || !((Boolean) ˏ.get(Integer.valueOf(i))).booleanValue()) && ˏ(getPermissionString(i), activity, false, i) && activity.shouldShowRequestPermissionRationale("android.permission.READ_PHONE_STATE")) {
            activity.requestPermissions(getPermissionString(14), 14);
            ˏ.put(Integer.valueOf(i), Boolean.valueOf(true));
        }
    }

    private static boolean ˏ(String[] strArr, Activity activity, boolean z, int i) {
        if (VERSION.SDK_INT < 23) {
            return false;
        }
        if (epz.ॱ(strArr)) {
            Logger.ˎ("PermissionChecker", "requestCode=" + i + " , no match permission check");
            return false;
        }
        boolean z2;
        for (String checkSelfPermission : strArr) {
            if (-1 == activity.checkSelfPermission(checkSelfPermission)) {
                z2 = true;
                break;
            }
        }
        z2 = false;
        if (!z2) {
            return false;
        }
        if (z) {
            activity.requestPermissions(strArr, i);
            ˏ.put(Integer.valueOf(i), Boolean.valueOf(true));
        }
        return true;
    }
}
